home *** CD-ROM | disk | FTP | other *** search
/ Java 1996 August / Java - Summer 1996.iso / rockridge / applet / anatomy / betaclasses / PrintThread.java < prev    next >
Encoding:
Java Source  |  1995-11-13  |  1.1 KB  |  48 lines

  1. import java.awt.Graphics;
  2. import java.awt.TextField;
  3.  
  4. public class PrintThread extends java.applet.Applet {
  5.  
  6.     TextField field = new TextField(80);
  7.     //boolean justRepainted = false;
  8.  
  9.     public void init() {
  10.     field.setEditable(false);
  11.     add(field);
  12.     resize(field.preferredSize());
  13.     show();
  14.         addItem("init:" + Thread.currentThread().getName() + " ");
  15.     }
  16.  
  17.     public void start() {
  18.         addItem("start:" + Thread.currentThread().getName() + " ");
  19.     }
  20.  
  21.     public void stop() {
  22.         addItem("stop:" + Thread.currentThread().getName() + " ");
  23.     }
  24.  
  25.     public void destroy() {
  26.         addItem("destroy:" + Thread.currentThread().getName() + " ");
  27.     }
  28.  
  29.     public void addItem(String newWord) {
  30.     String t = field.getText();
  31.  
  32.     System.out.println(newWord);
  33.     field.setText(t + newWord);
  34.     field.repaint();
  35.     }
  36.  
  37.     //public synchronized void update(Graphics g) {
  38.     //justRepainted = false;
  39.     //}
  40.  
  41.     public synchronized void paint(Graphics g) {
  42.     //if (!justRepainted) {
  43.             addItem("paint:" + Thread.currentThread().getName() + " ");
  44.         //justRepainted = true;
  45.     //}
  46.     }
  47. }
  48.